#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define vec vector<int>
#define y1 y_____hahahaha_____1

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); return x * sgn;}

const int N = 510;
const int mod = 998244353;

int n,m,ans;
char s[N][N];

int main(){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= n;i++) scanf("%s",s[i] + 1);
	ans = 1;
	for(int i = 2;i <= n + m;i++){
		int lst = 0; bool v = 0;
		for(int x = 1;x + 1 <= i && x <= n;x++){
			int y = i - x; if(y > m) continue;
			if(s[x][y] == '.') v = 1;
			else if(lst && s[x][y] ^ lst) return puts("0"),0;
			else lst = s[x][y];
		}
		if(v && !lst) ans = ans * 2 % mod;
	}
	cout<<ans<<endl;
	return 0;
}
